package top.sdaily.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.web.model.City;
import top.sdaily.web.service.CityService;

/**
 * Created by tsujishiki on 2017/2/17.
 */
@RestController
@RequestMapping
public class CityController {

    @Autowired
    CityService cityService;

    @RequestMapping(value = "province/{provinceId}/city", method = RequestMethod.GET)
    public ReturnBody getCitys(@PathVariable String provinceId) {
        return ReturnBody.success().setData(cityService.getAllCityByProvince(provinceId));
    }

    @GetMapping(value = "city/{id}")
    public ReturnBody getCityById(@PathVariable String id) {
        return ReturnBody.success().setData(cityService.getCityById(id));
    }

    @PostMapping(value = "city")
    public ReturnBody addCity(@RequestBody City city) {
        cityService.insertCity(city);
        return ReturnBody.success();
    }

    @PutMapping(value = "city")
    public ReturnBody updateCity(@RequestBody City city) {
        cityService.updateCity(city);
        return ReturnBody.success();
    }

}
